package com.xiaobingby.admin.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaobingby.admin.sys.entity.Role;
import com.xiaobingby.admin.sys.entity.RolePermission;
import com.xiaobingby.admin.sys.entity.UserRole;
import com.xiaobingby.admin.sys.mapper.RoleMapper;
import com.xiaobingby.admin.sys.mapper.RolePermissionMapper;
import com.xiaobingby.admin.sys.mapper.UserRoleMapper;
import com.xiaobingby.admin.sys.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.beans.Transient;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * sys_role 角色表 服务实现类
 * </p>
 *
 * @author XiaoBingBy
 * @since 2018-10-29
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IRoleService {

    @Autowired
    private RoleMapper roleMapper;

    @Autowired
    private UserRoleMapper userRoleMapper;

    @Autowired
    private RolePermissionMapper rolePermissionMapper;

    @Transient
    @Override
    public boolean deleteRoleUserPermission(Long[] ids) {
        int i = roleMapper.deleteBatchIds(Arrays.asList(ids));
        UpdateWrapper<UserRole> userRoleUpdateWrapper = new UpdateWrapper<>();
        userRoleUpdateWrapper.in("role_id", Arrays.asList(ids));
        int delete = userRoleMapper.delete(userRoleUpdateWrapper);
        UpdateWrapper<RolePermission> rolePermissionUpdateWrapper = new UpdateWrapper<>();
        rolePermissionUpdateWrapper.in("role_id", Arrays.asList(ids));
        int delete1 = rolePermissionMapper.delete(rolePermissionUpdateWrapper);
        return true;
    }
}
